package game.actors;

import edu.monash.fit2099.demo.forest.WanderBehaviour;
import edu.monash.fit2099.engine.actions.Action;
import edu.monash.fit2099.engine.actions.ActionList;
import edu.monash.fit2099.engine.actions.DoNothingAction;
import edu.monash.fit2099.engine.actors.Actor;
import edu.monash.fit2099.engine.actors.Behaviour;
import edu.monash.fit2099.engine.displays.Display;
import edu.monash.fit2099.engine.positions.GameMap;
import game.Abilities;
import game.actions.AttackAction;
import game.behaviours.AttackBehaviour;
import game.weapons.WolfBite;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * Wolf: 100 HP，咬击 50 伤害，50% 命中；邻格有玩家则优先攻击，否则游走。
 */
public class Wolf extends Actor {

    private final List<Behaviour> behaviours = new ArrayList<>();

    public Wolf() {
        super("Wolf", 'e', 100);
        // 设置本能武器：50 伤害，50% 命中，动词 "bites"
        this.setIntrinsicWeapon(new WolfBite());
        // 先尝试攻击（邻格有玩家）
        behaviours.add(new AttackBehaviour());
        // 否则游走
        behaviours.add(new WanderBehaviour());
    }

    /** 允许具有 CAN_ATTACK 能力的其他角色攻击狼 */
    @Override
    public ActionList allowableActions(Actor otherActor, String direction, GameMap map) {
        ActionList actions = new ActionList();
        if (otherActor.hasAbility(Abilities.CAN_ATTACK)) {
            actions.add(new AttackAction(this, direction));
        }
        return actions;
    }

    @Override
    public Action playTurn(ActionList actions, Action lastAction, GameMap map, Display display) {
        for (Behaviour behaviour : behaviours) {
            Action action = behaviour.generateAction(this, map);
            if (action != null) return action;
        }
        return new DoNothingAction();
    }
}
